/* include/define block for vcpp10    *
 * by marqueewinq, LKSH, 2011         */

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <fstream>
#include <utility>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>

/*             TYPES                   */

// long named types
#define UI unsigned int
#define LL long long
#define LD long double

// pairs
#define PP(type) pair <type, type>
#define II   pair <int,       int       >
#define ID   pair <int,       double    >
#define IB   pair <int,       bool      >
#define DD   pair <double,    double    >
#define DB   pair <double,    bool      >
#define LLLL pair <long long, long long >
#define LLD  pair <long long, double    >
#define LLB  pair <long long, bool      >

// vectors
#define VI  vector <int>
#define VVI vector <vector <int> >
#define V   vector
#define VD  vector <double>
#define VL  vector <long long>
#define VB  vector <bool>
#define VVB vector <vector <bool> >

// maps
#define M(first, second) map <first, second>
#define MII map <int, int>
#define MIB map <int, bool>
#define MIS map <int, string>
#define MLL map <long long, long long>
#define MLB map <long long, bool>
#define MLS map <long long, string>
#define MDD map <double, double>

/*           FUNCTIONALS               */

#define elif else if

// cycles
#define REP(count,n)    for(count = 0;      count <  n;  count++)
#define REPP(count,n)   for(count = 1;      count <= n;  count++)
#define REPSP(count,n)  for(count = 1;      count <  n;  count++)
#define RED(count,n)    for(count = n - 1;  count >= 0;  count--)
#define REDP(count,n)   for(count = n;      count >= 0;  count--)
#define REDSP(count,n)  for(count = n - 1;  count >  0;  count--)
#define INF             for(;;)
#define FORX(count,l,r) for(count = l;      count < r;   count++)

// pre-defined output of vector "data" with and without \n
#define OUTS(data) for(int count = 0; count < data.size(); count++) cout << data[count] << " ";
#define OUTL(data) for(int count = 0; count < data.size(); count++) cout << data[count];
#define OUTN(data) for(int count = 0; count < data.size(); count++) cout << data[count] << "\n";
#define NN << "\n"

// pre-defined input of vector "data" up to "n" elements
#define GETV(n,data) cin >> n; data.resize(n); for(int count = 0; count < n; count++) cin >> data[count];

LL dice() {srand(378901347); return (rand() | (rand() << 15));}

/*           CONSTANTS                 */

// some favorite seeds for randomize, hashes etc.
#define $ICQ 378901347  // my icq
#define $ICQ2 40561382  // my girlfriend's icq
#define $ICQ3 356288120 // my best friend's icq
#define $SKYPE "marqueewinq"
#define $MYPI 36.462159607207902 // pi ^ pi

// for static array ranges
#define $109 1000000000
#define $108 100000000
#define $107 10000000
#define $106 1000000
#define $105 100000
#define $104 10000

// max int, max LL etc.
#define $232 4294967296
#define $262 4611686018427387904

using namespace std;

/******************************/
const int cMaxn = $105;
int seq[cMaxn], magic[cMaxn], nxt[cMaxn];

int main()
{
#ifdef WIN32
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#else
	freopen("gladiolus.in","r",stdin);
	freopen("gladiolus.out","w",stdout);
#endif
    int n, m, k, b, count;
    cin >> n;
    
    cin >> seq[0] >> k >> b >> m; 
    
    REPSP(count,n)
    {
       seq[count] = (k * seq[count - 1] + b) % m;
       magic[count] = -1;
       nxt[count] = -1;
    }
       
    int len = 0;
    REP(count, n)
    {
       int left = 0, right = len, mid;
       while (left < right)
       {
	      mid = (left + right) / 2;
          if (seq[magic[mid]] >= seq[count]) 
             right = mid;
          else 
             left = mid + 1;  
       }
       if (left < len)
       {
          nxt[count] = magic[left - 1];
          magic[left] = count;
       }
       else
       {
          len++;
          magic[len - 1] = count;
          if (len > 1)
             nxt[count] = magic[len - 2];
          else
             nxt[count] = -1;
       }
    }
    
	// filling answer
    int temp = magic[len - 1];
    stack<int> ans;
    while (len > 0)
    {
        ans.push(seq[temp]);
        temp = nxt[temp];
        len--; 
    }
    
    while (ans.size() > 0)
    {
        cout << ans.top() << " ";
        ans.pop();
    }
    
    return 0;
}